
(define (equal? a b)
    (cond 
        ((and (not (pair? a)) (not (pair? b))) 
            (eq? a b)
        )        
        ((and (pair? a) (pair? b)) 
            (and 
                (equal? (car a) (car b))
                (equal? (cdr a) (cdr b))
            )
        )
        (else #f)
    )
)
(define (element-of-set? x set)
    (cond 
        ((null? set) #f)
        ((equal? x (car set)) #t)
        (else (element-of-set? x (cdr set)))
    )
)
(define (adjion-set x set)
    (cons x set)
)
(define (union-set set1 set2)
    (if (null? set1)
        set2
        (union-set 
            (cdr set1)
            (adjion-set 
                (car set1)
                set2
            )
        ) 
    )
)

(define (intersection-set set1 set2)
    (cond 
        (
            (or 
                (null? set1)
                (null? set2)
            )
            `()
        )
        ((element-of-set? (car set1) set2)
            (cons 
                (car set1)
                (intersection-set (cdr set1) set2)
            )
        )
        (else (intersection-set (cdr set1) set2))    
    )
)

(display (union-set (list 1 2 4 3 4) (list 2 3 6 8)))
(newline)
(display (intersection-set (list 1 2 4 3 4) (list 2 3 6 8)))
(exit)